package com.foton.bpc.all.util;

/**
 * @Author RenPu
 * @Date 2023/6/6 17:37
 * @Version 1.0
 * @Description: byte 转int 工具类的编写
 **/
public class ByteUtils {


    /**
     *  byte[] ---> int
     * @param bytes
     * @return
     */
   public  static int Byte2Int(byte[] bytes){

       int offset = 0;
       int value;
       value = ((bytes[offset] & 0xFF)
               | ((bytes[offset + 1] & 0xFF) << 8)
               | ((bytes[offset + 2] & 0xFF) << 16)
               | ((bytes[offset + 3] & 0xFF) << 24));
       return value;

   }


    /**
     *  int ---> byte[]
     * @param length
     * @return
     */
    public static byte[] Int2Byte(int length) {
        byte[] b = new byte[4];
        b[0] = (byte) (length & 0xff);
        b[1] = (byte) (length >> 8 & 0xff);
        b[2] = (byte) (length >> 16 & 0xff);
        b[3] = (byte) (length >> 24 & 0xff);
        return b;
    }
}
